<?php

/**
 * 
 *
 */
class AController extends Controller
{

	public $layout='/layouts/column1';
	
	public function __construct($id, $module = null) {
		//echo $id;
		//echo $this->action->id;
		//echo(Yii::app()->controller->action->id);
		parent::__construct($id, $module);
	}

	public function init()
	{
		//echo Yii::app()->controller->id;
		//echo Yii::app()->controller->action->id;
		//print_r(Yii::app()->getRequest()->getPathInfo());
		$this->userInfo = Yii::app()->session['userInfo'];
		//print_r(Yii::app()->session['userGroup']);
		$c = Yii::app()->controller->id;
		$a =  $this->_getAction($c);
		//echo $c;
		//echo $a;
		//无管理员权限
		if(!$this->_isAdmin())
		{
			$this->showAlert(array('type'=>'2','content'=>'抱歉！没有权限！','url'=>'transfer/start'));
		}
		//模块权限
		if(!HrAdminRight::model()->checkAccess($c,$a))
		{
			$this->showAlert(array('type'=>'2','content'=>'抱歉！没有权限！','url'=>'admincp/default/index'));
		}
		
		
		$this->currentUrl = str_replace('?'.$_SERVER['QUERY_STRING'],'',$this->currentUrl);
	}

	public function initData($name)
	{
		$tinit = new Tinit();
		return $tinit->$name();
	}

	/**
	 * 跳转
	 */
	public function showAlert($message){
		$this->layout='//layouts/alert';
		$this->render('//site/alert',array(
			'message'=>$message,
		));
		exit;
	}

	/**
	 * 是否有访问后台权限 
	 */
	protected function _isAdmin()
	{
		return Yii::app()->session['userGroup']['admincp']>=1?1:0;

		/*
		$adminManager = InitModel::getAdmin();
		$adminCon = array('admin','coins','spendType');
		if(in_array($this->id,$adminCon)){
			if(!in_array($this->userInfo['username'],$adminManager)){
				$res = array('url'=>$this->createUrl('site/index'),'msg'=>Yii::t('common','没有权限'),'code'=>2);
				$this->showMessage($res);
			}
		}
		*/
	}


	protected function _getAction($c)
	{
		$a = explode('/', Yii::app()->getRequest()->getPathInfo());
		if(!empty($a))
		{
			while(list($key , $val) = each($a)) {
				if($val == $c) return current($a);
			}
		}
		else
			return null;
		
	}
	
}